<template>
  <view class="qualificationsStatus" @click="qualificationsOverdue">
    <view class="styles">
      <text> {{ tips }} </text>
      <uni-icons type="forward" size="14" color="#ef231b"></uni-icons>
    </view>
  </view>
</template>

<script>
import jwtDecode from 'jwt-decode'

export default {
  data() {
    return {
      status: false,
      tips: ''
    }
  },
  created() {
    this.qualificationsStatus()
  },
  methods: {
    qualificationsOverdue() {
      let a = JSON.parse(
        jwtDecode(uni.getStorageSync('token')).userContext.replace('\\', '')
      ).purchaserApplyStatus
      if (a === 'WAIT_AUDIT') {
        uni.showToast({
          icon: 'none',
          title: '正在审核中，请耐心等待',
          mask: true
        })
        return
      }
      if (a === 'PASS') {
        this.status = false
        uni.showToast({
          icon: 'none',
          title: '已通过',
          mask: true
        })
        return
      }
      if (a !== 'APPLY') {
        uni.navigateTo({
          url: `/pages_user/reg/qualificationList`
        })
      }
      if (a === 'APPLY') {
        uni.navigateTo({
          url: `/pages_user/reg/enterpriseType`
        })
      }
    },
    qualificationsStatus() {
      if (uni.getStorageSync('token')) {
        let a = JSON.parse(jwtDecode(uni.getStorageSync('token')).userContext.replace('\\', ''))
        if (
          a.purchaserApplyStatus === 'APPLY' ||
          a.purchaserApplyStatus === 'REAPPLY' ||
          a.purchaserApplyStatus === 'REFUSE'
        ) {
          this.status = true
          this.tips = '您的相关资质尚未提交，请尽快上传并邮寄，以免影响您的采购计划~'
          return
        }
        if (a.purchaserApplyStatus === 'MAKE_UP' || a.purchaserApplyStatus === 'RENEW') {
          this.status = true
          this.tips = '您的相关资质需要补充，请尽快上传并邮寄，以免影响您的采购计划~'
          return
        }
        if (a.purchaserApplyStatus === 'EXPIRE') {
          this.status = true
          this.tips = '您的相关资质即将过期或已过期，请尽快上传并邮寄，以免影响您的采购计划~'
          return
        }
        if (a.purchaserApplyStatus === 'WAIT_AUDIT') {
          this.status = true
          this.tips = '您的相关资质正在审核中，请耐心等待~'
          return
        }
        if (a.purchaserApplyStatus === 'PASS' || a.purchaserApplyStatus === 'REVIEW') {
          this.status = false
        } else {
          this.status = false
        }
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.qualificationsStatus {
  width: 100%;
  height: 69rpx;
  position: fixed;
  left: 0;
  bottom: 0;
  z-index: 100;

  .styles {
    height: 69rpx;
    display: flex;
    flex-flow: row wrap;
    justify-content: space-between;
    align-items: center;
    background: #ffe9e8;
    padding: 0 28rpx;

    text {
      font-size: 21rpx;
      color: #ef231b;
    }
  }
}
</style>
